package com.campsys.common.util;

import com.campsys.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.apache.shiro.subject.Subject;

public class ShiroUtils {
    
    private static final int HASH_ITERATIONS = 3;
    
    public static String sha256(String password, String salt) {
        return new Sha256Hash(password, salt, HASH_ITERATIONS).toHex();
    }
    
    public static Subject getSubject() {
        return SecurityUtils.getSubject();
    }
    
    public static User getCurrentUser() {
        return (User) getSubject().getPrincipal();
    }
    
    public static Long getUserId() {
        return getCurrentUser().getId();
    }
    
    public static void logout() {
        getSubject().logout();
    }
    
    public static String encryptPassword(String password, String salt) {
        String hashedPassword = sha256(password, salt);
        System.out.println("Password: " + password);
        System.out.println("Salt: " + salt);
        System.out.println("Hashed Password: " + hashedPassword);
        return hashedPassword;
    }
} 